package com.wanrue.tcc.context;

import com.wanrue.tcc.enums.Status;
import lombok.Data;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 事务上下文
 * Created by wenjie on 11/08/18.
 */
@Data
public class Context implements Serializable {

    private static final long serialVersionUID = -8199390103169700387L;

    /**
     * 分布式事务xid
     */
    private Xid xid;

    /**
     * 事务下文状态
     */
    private Status status;

    /**
     * 事务下文附件
     */
    private Map<String, String> attachments = new ConcurrentHashMap<String, String>();

    public Context(Xid xid, Status status) {
        this.xid = xid;
        this.status = status;
    }

    public void put(String key, String val) {
        attachments.put(key, val);
    }

}